﻿#define ORACLE
using QueryZJK.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QueryZJK.Helpers
{
    //对于那些可能多次用到的值其实应该缓存起来
    public static class ConfigHelper
    {
        public static DbType DbType
        {
            get
            {
#if DEBUG
                string dbType = "SQLSERVER";
#else
                string dbType = GetAppSettingValueByKey("DbType").ToUpperInvariant();
#endif

                return EnumHelper.Parse<DbType>(dbType);
            }
        }

        public static String DbConnectStr
        {
            get
            {
                string dbConnectStr = string.Empty;
#if DEBUG
                switch (DbType)
                {
                    case DbType.ORACLE:
                        dbConnectStr = "Host=172.10.0.23;Port=1521;User ID=BDCDJ_GXJH;Password=BDCDJ_GXJH;SID=orcl";
                        break;
                    case DbType.SQLSERVER:
                        dbConnectStr = "Data Source = 10.0.0.1; Initial Catalog = LandToKT; User Id = bdc_kt; Password = bdc!@#$%;";
                        break;
                    default:
                        break;
                }
#else
                switch (DbType)
                {
                    case DbType.ORACLE:
                        dbConnectStr = GetAppSettingValueByKey("OracleDbConnectStr");
                        break;
                    case DbType.SQLSERVER:
                        dbConnectStr = GetAppSettingValueByKey("SqlServerDbConnectStr");
                        break;
                    default:
                        break;
                }
#endif
                return dbConnectStr;
            }

        }

        private static Dictionary<string, string> cache = new Dictionary<string, string>(10);
        static string GetAppSettingValueByKey(string key)
        {
            if (!cache.ContainsKey(key))
            {
                string val = System.Configuration.ConfigurationManager.AppSettings[key];
                cache.Add(key, val);
            }
            return cache[key];
        }
    }
}
